package View;

import home.Config;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.BevelBorder;

public class Ricerca extends JPanel implements ActionListener{
	
	private static final long serialVersionUID = 7879143344382934850L;
	
	private JPanel content = new JPanel(new BorderLayout());
	
	private JPanel sidebar = new JPanel(new GridBagLayout());
	
	private JPanel header = new JPanel(new FlowLayout(FlowLayout.LEFT));

	public Ricerca(){
		
		super(new GridBagLayout());
		
		GridBagConstraints con = new GridBagConstraints();
		
		this.setHeader(header);
		con.fill = GridBagConstraints.BOTH;
		con.weightx = 0.5;
		con.weighty = 0;
		con.gridx = 0;
		con.gridy = 0;
		con.gridwidth = 4;
		this.add(header, con);
		
		this.setContent(content);
		con.fill = GridBagConstraints.BOTH;
		con.weightx = 0.165;
		con.weighty = 0.5;
		con.gridx = 0;
		con.gridy = 1;
		con.gridwidth = 1;
		this.add(content, con);
		
		this.setSidebar(sidebar);
		con.fill = GridBagConstraints.BOTH;
		con.weightx = 0.5;
		con.weighty = 0.5;
		con.gridx = 1;
		con.gridy = 1;
		con.gridwidth = 3;
		this.add(sidebar, con);
		
	}
	
	private JPanel setContent(JPanel panel){
		
		panel.setBackground(Config.getConfig().getRosa());
		panel.setMinimumSize(new Dimension(240,500));
		panel.setPreferredSize(new Dimension(240,500));
		panel.setBorder(BorderFactory.createLineBorder(Color.white));
		
		JButton cerca = new JButton("Cerca");
		cerca.addActionListener(this);
		cerca.setMinimumSize(new Dimension(240,60));
		cerca.setPreferredSize(new Dimension(240,60));
		cerca.setBackground(Config.getConfig().getCaramello());
		cerca.setFont(Config.getConfig().getFont().deriveFont((float)20));
		cerca.setForeground(Color.white);
		cerca.setFocusPainted(false);
		cerca.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED,new Color(165,64,66),new Color(204,108,110),null,new Color(108,55,56)));
		panel.add(cerca,BorderLayout.SOUTH);
		
		return panel;
		
	}
	
	private JPanel setSidebar(JPanel panel){
		
		panel.setBackground(Config.getConfig().getRosaChiaro());
		panel.setBorder(BorderFactory.createLineBorder(Color.white));
		panel.setMinimumSize(new Dimension(720,500));
		panel.setPreferredSize(new Dimension(720,500));
		
		GridBagConstraints c = new GridBagConstraints();

		JLabel l0 = new JLabel("Giorno/Notte");
		l0.setBorder(BorderFactory.createLineBorder(Color.white));
		l0.setForeground(Color.white);
		l0.setHorizontalAlignment(SwingConstants.CENTER);
		l0.setFont(Config.getConfig().getFont().deriveFont((float)14));
		c.fill = GridBagConstraints.BOTH;
		c.weightx = 0.5;
		c.weighty = 0.15;
		c.gridx = 0;
		c.gridy = 0;
		panel.add(l0,c);
		
		JPanel p0 = new JPanel();
		p0.setBackground(Config.getConfig().getMarrone());
		p0.setBorder(BorderFactory.createLineBorder(Color.white));
		c.fill = GridBagConstraints.BOTH;
		c.weightx = 0.5;
		c.weighty = 0.6;
		c.gridx = 0;
		c.gridy = 1;
		panel.add(p0,c);
		
		JLabel l1 = new JLabel("Occasioni");
		l1.setBorder(BorderFactory.createLineBorder(Color.white));
		l1.setForeground(Color.white);
		l1.setHorizontalAlignment(SwingConstants.CENTER);
		l1.setFont(Config.getConfig().getFont().deriveFont((float)14));
		c.fill = GridBagConstraints.BOTH;
		c.weightx = 0.5;
		c.weighty = 0.15;
		c.gridx = 0;
		c.gridy = 2;
		panel.add(l1,c);
		
		JPanel p1 = new JPanel();
		p1.setBackground(Config.getConfig().getMarrone());
		p1.setBorder(BorderFactory.createLineBorder(Color.white));
		c.fill = GridBagConstraints.BOTH;
		c.weightx = 0.5;
		c.weighty = 0.6;
		c.gridx = 0;
		c.gridy = 3;
		panel.add(p1,c);
		
		JLabel l2 = new JLabel("Colore Occhi");
		l2.setBorder(BorderFactory.createLineBorder(Color.white));
		l2.setForeground(Color.white);
		l2.setHorizontalAlignment(SwingConstants.CENTER);
		l2.setFont(Config.getConfig().getFont().deriveFont((float)14));
		c.fill = GridBagConstraints.BOTH;
		c.weightx = 0.5;
		c.weighty = 0.15;
		c.gridx = 0;
		c.gridy = 4;
		panel.add(l2,c);
		
		JPanel p2 = new JPanel();
		p2.setBackground(Config.getConfig().getMarrone());
		p2.setBorder(BorderFactory.createLineBorder(Color.white));
		c.fill = GridBagConstraints.BOTH;
		c.weightx = 0.5;
		c.weighty = 0.6;
		c.gridx = 0;
		c.gridy = 5;
		panel.add(p2,c);
		
		JLabel l3 = new JLabel("Colore Capelli");
		l3.setBorder(BorderFactory.createLineBorder(Color.white));
		l3.setForeground(Color.white);
		l3.setHorizontalAlignment(SwingConstants.CENTER);
		l3.setFont(Config.getConfig().getFont().deriveFont((float)14));
		c.fill = GridBagConstraints.BOTH;
		c.weightx = 0.5;
		c.weighty = 0.15;
		c.gridx = 0;
		c.gridy = 6;
		panel.add(l3,c);
		
		JPanel p3 = new JPanel();
		p3.setBackground(Config.getConfig().getMarrone());
		p3.setBorder(BorderFactory.createLineBorder(Color.white));
		c.fill = GridBagConstraints.BOTH;
		c.weightx = 0.5;
		c.weighty = 0.6;
		c.gridx = 0;
		c.gridy = 7;
		panel.add(p3,c);
		
		JLabel l4 = new JLabel("Riepilogo");
		l4.setBorder(BorderFactory.createLineBorder(Color.white));
		l4.setForeground(Color.white);
		l4.setHorizontalAlignment(SwingConstants.CENTER);
		l4.setFont(Config.getConfig().getFont().deriveFont((float)18));
		c.fill = GridBagConstraints.BOTH;
		c.weightx = 0.5;
		c.weighty = 0.3;
		c.gridx = 0;
		c.gridy = 8;
		panel.add(l4,c);
		
		JPanel p4 = new JPanel();
		p4.setBackground(Config.getConfig().getMarrone());
		p4.setBorder(BorderFactory.createLineBorder(Color.white));
		c.fill = GridBagConstraints.BOTH;
		c.weightx = 0.5;
		c.weighty = 1;
		c.gridx = 0;
		c.gridy = 9;
		panel.add(p4,c);
		
		return panel;
		
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		
		Risultati ris = new Risultati();
		Clio.AggiornaGUI(ris, "risultati");
		
	}
	
	private JPanel setHeader(JPanel panel){
		
		// custumizza l'header
		panel.setBackground(Config.getConfig().getMarrone());
		panel.setBorder(BorderFactory.createLineBorder(Color.white));
		panel.setPreferredSize(new Dimension(966, 30));
		panel.setMinimumSize(new Dimension(966, 30));
		
		// crea il primo bottone e lo aggiunge
		JButton home = new JButton();
		Home.f(home, "home", true);
		panel.add(home);
		
		//aggiungi separatore
		Home.freccia(panel);
		
		// crea il secondo bottone e lo aggiunge
		JButton strumenti = new JButton();
		Home.f(strumenti, "cosmetici e strumenti", false);
		panel.add(strumenti);
		
		return panel;
	}

}
